
export const heatMapOptions = (params, baseVal/*基准值*/) => {

  const xAxis = [] //横坐标name
  const yAxis = [] //纵坐标name
  const data = []

  params.forEach(element => {
    // 获取 xAxis
    if(!xAxis.includes(element.dataTime.slice(5))){
      xAxis.push(element.dataTime.slice(5))
    }
    // 获取 yAxis
    if(!yAxis.includes(element.machineId.slice(4))){
      yAxis.unshift(element.machineId.slice(4))
    }
  })

  params.forEach(element => {
    data.push([xAxis.indexOf(element.dataTime.slice(5)), yAxis.indexOf(element.machineId.slice(4)), element.tenDayAst])
  })

    const heatMapOption = {
      tooltip: {
        borderWidth: 1,
        borderColor: '#ccc'
      },
      grid: {
        left: '0',
        right: '1%',
        top: '0',
        bottom: '6%',
        containLabel: true
      },
      xAxis: [{
        show: false,
        type: 'category',
        data: xAxis
      }, {
        type: 'category',
        data: xAxis,
        splitArea: {
          show: true
        },
        axisLabel: {
          show: true,
          textStyle: {
            color: 'blue'
          },
          interval: 0,
          rotate: "-45"
        },
        axisTick: {
          show: true
        },
        triggerEvent: true
      }],
      yAxis: {
        type: 'category',
        data: yAxis,
        splitArea: {
          show: true
        },
        axisLabel: {
          show: true,
          textStyle: {
            color: 'blue',
            fontWeight: 600
          }
        },
        axisTick: {
          show: false
        },
        triggerEvent: true
      },
      visualMap: {
        min: baseVal - (baseVal * 0.2), // 标准值 - 标准值 * 0.2
        max: baseVal + (baseVal * 0.2), // 标准值 + 标准值 * 0.2
        calculable: true,
        itemWidth: 12,
        precision: 2,
        type :'continuous',
        orient: 'horizontal',
        left: 'center',
        bottom: '0',
        inRange: {
          // color: ['#15B1F4', '#16c573', '#d18a17', '#ffac1d', '#D1621D'],
          color: ['#008000', '#33cc33', '#66ff66', '#ffffff', '#ff9999', '#ff5050', '#cc0000']
        }
      },
      series: [{
        // name: '数值',
        type: 'heatmap',
        data: data,
        label: {
          show: true,
          textStyle: {
            color: "#000" // 图标中的字体颜色
          }
        },
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }]
    }

  return {
    xAxis,
    yAxis,
    data,
    heatMapOption
  }
}

// 筛选颜色
// function setColors(val, index) {
//   let obj = {}
//   let color = null
//   if (index == 0) {
//     color = "#0288d1"
//   } else if (index == 1) {
//     color = "#16c573"
//   } else {
//     if (val <= 800) {
//       color = '#15B1F4'
//     } else if (val > 800 && val < 1000) {
//       color = '#ffac1d'
//     } else if (val >= 1000) {
//       color = 'red'
//     }
//   }
//   if (color != null) {
//     obj = {
//       normal: {
//         color: color
//       }
//     }
//   }
//   return obj
// }